import javax.naming.PartialResultException;
import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86138
 * Date: 2024-05-13
 * Time: 22:57
 */
public class May_13 {
    public static void main(String[] args) {
        //递归求解汉诺塔问题
    }




    public static boolean judge(int[] array) {
        //给你一个整数数组 arr，请你判断数组中是否存在连续三个元素都是奇数的情况：如果存在，请返回 true ；否则，返回 false 。

        int count = 0;
        int i = 0;
        for (i = 0; i < array.length; i++) {
            if(array[i]%2 != 0){
                count++;
                if(count == 3){
                    return true;
                }
            }else{
                count = 0;
            }
        }
        return false;
    }

    public static void main9(String[] args) {
        int[] array = {2,6,4,1};
        //int[] array = {1,2,34,3,4,5,7,23,12};
        boolean ret = judge(array);
        System.out.println(ret);
    }



    public static void main8(String[] args) {
        //给定一个大小为 n 的数组，找到其中的多数元素。多数元素是指在数组中出现次数 大于 ⌊ n/2 ⌋ 的元素。
        //你可以假设数组是非空的，并且给定的数组总是存在多数元素。
        //int[] array = {3,2,3};
        int[] array = {2,2,1,1,1,2,2};
        Arrays.sort(array);//排序后一半前一个是最多的而且大于n/2
        System.out.println(array[array.length>>>1]);
    }



    public static void main7(String[] args) {
        //给定一个非空整数数组，除了某个元素只出现一次以外，其余每个元素均出现两次。找出那个只出现了一次的元素。
        int[] array = {4,1,2,1,2};
        //int[] array = {3,3,6,2,6,8,2,9,8,5,5};
        //int[] array = {2,2,1};
        int ret = 0;
        int i = 0;
        for (i=0; i<array.length;i++){
            ret = ret ^ array[i];
        }
        System.out.println(ret);
        }


    public static void main6(String[] args) {
        //两数之和
        int[] array= {2,7,11,15};
        int[] ret = {0,0};
        //趟数
        int taget = 9;
        for(int i = 0;i<array.length;i++){
            for(int j = i+1;j<array.length-1;j++){
                if(array[i]+array[j] == taget){
                    ret[0] = i;
                    ret[1] = j;
                }
            }
        }
        System.out.println(Arrays.toString(ret));
    }


    public static void bubbleSort(int[] array) {
        for(int i = 0;i < array.length-1;i++){
            boolean flg = false;
            for(int j = 0;j < array.length-i-1;j++){
                if(array[j]>array[j+1]){
                    int t = array[j];
                    array[j] = array[j+1];
                    array[j+1] = t;
                    flg = true;
                }
            }
            if(flg==false){
                return;
            }
        }
    }

    //冒泡排序
    public static void main5(String[] args) {
        int[] array = {1,6,3,23,98,55,54,23,45};
        bubbleSort(array);
        System.out.println(Arrays.toString(array));
    }


    //二分查找
    public static void main4(String[] args) {
        int[] array = {3,4,5,6,7,8,9,10,11,26,47};
        int left = 0;
        int right = array.length-1;
        int mid = (left+right)/2;
        int key = 5;
        int idex = 0;
        while (left<=right){
            mid = (left+right)/2;
            if(array[mid]==key){
                System.out.println("find!");
                return;
            }else if(array[mid]<key){
                left = mid+1;

            }else{
                right = mid-1;
            }
        }
        System.out.println("not find!");

    }



    public static void main3(String[] args) {
        //调整数组顺序使得奇数位于偶数之前。调整之后，不关心大小顺序。
        //如数组：[1,2,3,4,5,6]
        //调整后可能是：[1, 5, 3, 4, 2, 6]
        int[] array= {1,2,3,4,5,6};
        int left = 0;
        int right = array.length-1;
        while(left<right){
            while(left<right && array[left]%2!=0){//left<right判断防止越界
                left++;
            }
            while(left<right && array[right]%2==0){
                right--;
            }
            int t = array[left];
            array[left] = array[right];
            array[right] = t;
        }


        System.out.println(Arrays.toString(array));
    }

    public  static void transform(int[] array){
        int i = 0;
        for (i = 0; i < array.length; i++) {
            array[i] = array[i] * 2;
        }
    }

    public static void main2(String[] args) {
        int[] array = {1,2,3};
        transform(array);
        System.out.println(Arrays.toString(array));
    }



    public static void main1(String[] args) {
        int [] array = {1,2,3,4,5};
        System.out.println(array);//打印地址
        System.out.println(Arrays.toString(array));
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i] + " ");
        }
    }
}
